'use strict';
const db = uniCloud.database();

exports.main = async (event, context) => {
	const { id } = event;
	console.log('获取用户ID：', id);

	if (!id) {
		return { code: 400, msg: '缺少用户ID' };
	}

	try {
		// 查询UserInfo集合中对应ID的用户数据
		const res = await db.collection('UserInfo')
			.where({ _id: id })
			.get();

		return {
			code: 200,
			msg: '查询成功',
			data: res.data
		};
	} catch (error) {
		console.error('查询失败：', error);
		return {
			code: 500,
			msg: '查询失败'
		};
	}
};